﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Linq;
using Nwsfeed;

namespace nwsfeed
{
	/// <summary>
	/// Interaction logic for AddFeedWindow.xaml
	/// </summary>
    public partial class SettingsWindow : Window, INotifyPropertyChanged
	{
        public MainWindow mainWindow;
		
		private String windowTitle;
        public String WindowTitle { get { return windowTitle; } set { windowTitle = value; OnPropertyChanged("WindowTitle"); } }

        private String titleSizeLabel;
        public String TitleSizeLabel { get { return titleSizeLabel; } set { titleSizeLabel = value; OnPropertyChanged("TitleSizeLabel"); } }

        private String bodySizeLabel;
        public String BodySizeLabel { get { return bodySizeLabel; } set { bodySizeLabel = value; OnPropertyChanged("BodySizeLabel"); } }
		
		public double TitleFontSize
		{
			get {   return mainWindow.App.TitleFontSize;    }
			set {
                    mainWindow.TitleFontSize = value;
					TitleSizeLabel = "Title text size " + (int)TitleFontSize + " px";
				}
		}
		
		public double BodyFontSize
		{
            get {   return mainWindow.App.BodyFontSize; }
			set {
                    mainWindow.BodyFontSize = value; 
					BodySizeLabel = "Body text size " + (int)BodyFontSize + " px";
				}
		}
		
		public SettingsWindow()
		{
			this.InitializeComponent();
            this.init();
		}

        public SettingsWindow(MainWindow mainWindow)
        {
            this.mainWindow = mainWindow;
            this.InitializeComponent();
			Loaded +=new System.Windows.RoutedEventHandler(SettingsWnd_Loaded);
            init();
        }

        private void init()
        {
            this.DataContext = this;

            // init UI properties
			WindowTitle = "Preferences";
			TitleSizeLabel = "Title text size: " + (int)TitleFontSize + " px";
			BodySizeLabel = "Body text size: " + (int)BodyFontSize + " px";

        }


		private void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
		

		private void xButton_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			this.Close();
		}

        private void SettingsWnd_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
        	var style = (Style)Resources["WindowStyleModal"];
            this.Style = style;
        }

        private void SettingsWnd_Activated(object sender, System.EventArgs e)
        {
        	mainWindow.activeDialog = this;
        }

        private void SettingsWnd_Closed(object sender, System.EventArgs e)
        {
        	 mainWindow.activeDialog = null;

             mainWindow.App.SaveProfileSettings();
        }

}
}